package com.lemon.smartsafetynew.ui.activity.record;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.AppManager;
import com.lemon.smartsafetynew.entity.common.DateTypeEnum;
import com.lemon.smartsafetynew.entity.record.EmergenVo;
import com.lemon.smartsafetynew.ui.activity.base.SwipeBackActivity;
import com.lemon.smartsafetynew.util.common.CommonUtil;
import com.lemon.smartsafetynew.util.constants.KeyConstants;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 应急物资详情
 * Created by JiangAn on 2018/5/25.
 */

public class RecordEmergencyDetailActivity extends SwipeBackActivity {

    @Bind(R.id.iv_return)
    ImageView ivReturn;
    @Bind(R.id.tv_equipment_name)
    TextView tvEquipmentName;
    @Bind(R.id.tv_belong_large_class)
    TextView tvBelongLargeClass;
    @Bind(R.id.tv_belong_small_class)
    TextView tvBelongSmallClass;
    @Bind(R.id.tv_involve_facilities)
    TextView tvInvolveFacilities;
    @Bind(R.id.tv_emergency_number)
    TextView tvEmergencyNumber;
    @Bind(R.id.tv_check_date)
    TextView tvCheckDate;
    @Bind(R.id.tv_expire_date)
    TextView tvExpireDate;
    @Bind(R.id.tv_material_status)
    TextView tvMaterialStatus;
    @Bind(R.id.tv_space_remark)
    TextView tvSpaceRemark;

    private static EmergenVo emergenVo;
    private Boolean isShowReturn = false;
    @Override
    protected void initTitle() {
        this.setBarTitle(getString(R.string.record_emergency_info));
    }

    @Override
    protected void getBundleArgs() {
        super.getBundleArgs();

        Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            isShowReturn = bundle.getBoolean("isShowReturn");
            if (bundle.containsKey(KeyConstants.KEY_RECORD_EMERGENCY_VO)) {
                emergenVo = (EmergenVo) bundle.getSerializable(KeyConstants.KEY_RECORD_EMERGENCY_VO);
            }
        }
    }

    @Override
    protected void callFinish() {
        AppManager.getAppManager().finishActivity(RecordEmergencyDetailActivity.this);
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_record_emergency_detail;
    }

    @Override
    protected void initViews() {
        super.initViews();

        if (isShowReturn) {
            ivReturn.setVisibility(View.VISIBLE);
        } else {
            ivReturn.setVisibility(View.INVISIBLE);
        }

        initEmergencyView();
    }

    /**
     * 应急物资信息详情页初始化
     */
    private void initEmergencyView() {

        tvEquipmentName.setText(CommonUtil.avoidNullString(emergenVo.getEmergency_equipment_name()));
        tvBelongLargeClass.setText(CommonUtil.avoidNullString(emergenVo.getBigType()));
        tvBelongSmallClass.setText(CommonUtil.avoidNullString(emergenVo.getSmallType()));
        tvInvolveFacilities.setText(CommonUtil.avoidNullString(emergenVo.getProcess_facilities()));
        tvEmergencyNumber.setText(CommonUtil.avoidNullString(emergenVo.getCount()));

        tvCheckDate.setText(CommonUtil.secondToTimeStr(emergenVo.getCheck_date(), DateTypeEnum.DAY));
        tvExpireDate.setText(CommonUtil.secondToTimeStr(emergenVo.getEnd_time(), DateTypeEnum.DAY));
        tvMaterialStatus.setText(CommonUtil.avoidNullString(emergenVo.getStatus()));
        tvSpaceRemark.setText(CommonUtil.avoidNullString(emergenVo.getRemark()));
    }

    @Override
    protected void initListener() {
        super.initListener();
        ivReturn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AppManager.getAppManager().finishActivity(RecordEmergencyDetailActivity.this);
                AppManager.getAppManager().finishActivity(RecordEmergencyActivity.class);
            }
        });
    }


}



